package design.mode.builder;

/**
 * @author ZhongMingde on 2021/10/28
 */

public class ResourcePoolConfig {
    private String name;
    private int maxTotal;
    private int maxIdle;
    private int minIdle;

    private ResourcePoolConfig(Builder builder) {
        this.name = builder.name;
        this.maxTotal = builder.maxTotal;
        this.maxIdle = builder.maxIdle;
        this.minIdle = builder.minIdle;
    }

    public static class Builder {

        private String name;
        private int maxTotal;
        private int maxIdle;
        private int minIdle;

        public Builder name(String name) {
            this.name = name;
            return this;
        }

        public Builder(String name){
            this.name = name;
        }

        public Builder maxTotal(int maxTotal) {
            this.maxTotal = maxTotal;
            return this;
        }

        public Builder maxIdle(int maxIdle) {
            this.maxIdle = maxIdle;
            return this;
        }

        public Builder minIdle(int minIdle) {
            this.minIdle = minIdle;
            return this;
        }

        public ResourcePoolConfig build() {
            return new ResourcePoolConfig(this);
        }
    }

    public static void main(String[] args) {
        ResourcePoolConfig resourcePoolConfig = new Builder("我")
                .maxIdle(1)
                .minIdle(0)
                .build();
        System.out.println(resourcePoolConfig.maxIdle);
    }
}
